console.log('into contentScripts');
/*
var tag = ['a','abbr','acronym','address','applet','area','article','aside','audio','b','base','basefont','bdi','bdo','big','blockquote','body','br','button','canvas','center','caption','cite','code','col','colgroup','command','datalist','dd','del','details','dfn','dialog','dir','div','dl','dt','em','embed','fieldset','figcaption','figure','font','footer','form','frame','frameset','h1','head',
'header','hgroup','hr','html','i','iframe','img','input','ins','kbd','keygen','label','legend','li','link','main','map','mark','menu','menuitem','meta','meter','nav','noframes','noscript','object','ol','optgroup',
'option','output','p','param','pre','progress','q','rp','rt','ruby','s','samp','script','section','select','source','span','strike','strong','style','sub','summary','sup',
'table','tbody','td','textarea','tfoot','th','thead','time','title','tr','track','tt','u','ul','var','video','wbr',];

var attr = ['accesskey','class','contenteditable','contextmenu','dir','draggable','dropzone','hidden','id','lang','spellcheck','styletabindex','title','translate',
'challenge','keytype','accept','autocomplete','autofocus','checked','disabled','pattern','placeholder','required','step',
'border','alt','crossorigin','hspace','ismap','usemap','scrolling','seamless','srcdoc','frameborder','longdesc','marginheight','marginwidth','sandbox','mainfest','xmlns','noshade',
'profile','cols','rows','src','accept-charset','action','enctype','novalidate','target','face','size','form',
'compact','open','datetime','icon','label','radiogroup','align','char','charoff','span','valign','width','height','formnovalidate',
'formtarget','value','formaction','formenctype','formmedthod','alink','background','bgcolor','link','text','vlink','cite','color','autoplay','controls','loop','muted','preload',
'coords','hreflang','media','nohref','rel','shape','type','code','object','archive','codebase','vspace','style','charset','download','href','name','rev',
'abbr','aconym','audioTracks','autoplay','buffered','controller','controls','crossOrigin','currentSrc','currentTime','defaultMuted','defaultPlaybackRate','duration','ended','error','loop','mediaGroup',
'muted','networkState','paused','playbackRate','played','preload','readyState','seekable','seeking','startDate','textTracks',
'videoTracks','volume','fillStyle','strokeStyle','shadowColor','shadowBlur','shadowOffsetX','shadowOffsetY'];

var method = ['onafterprint','onbeforeprint','onbeforeunload','onerror','onhaschange','onload','onmessage','onoffline','ononline','onpagehide','onpageshow',
'onpopstate','onredo','onresize','onstorage','onundo','onunload','onblur','onchange','oncontextmenu','onfocus','onformchange','onforminput','oninput',
'oninvalid','onreset','onselect','onsubmit','onkeydown','onkeypress','onkeyup','onclick','ondblclick','ondrag','ondragend','ondragenter',
'ondragleave','ondragover','ondragstart','ondrop','onmousedown','onmousemove','onmouseout','onmouseover','onmouseup','onmousewheel','onscroll','onabort',
'oncanplaythrough','ondurationchange','onemptied','onended','onerror','onloadeddata','onloadedmetadata','onloadstart','onpause','onplay','onplaying','onprogress',
'onratechange','onreadystatechange','onseeked','onseeking','onstalled','onsuspend','ontimeupdate','onvolumechange','onwaiting','abort','canplaythrough',
'durationchange','emptied','ended','error','loadeddata','loadedmetadata','loadstart','paused','play','playing','progress','ratechange',
'seeked','seeking','stalled','suspend','timeupdate','volumechange','waiting'];



var url = 'http://localhost/index.php?';

function getRandomValue(arr)
{
    return arr[Math.floor(Math.random() * arr.length)];
}

function getTag()
{
    return {
        'm_tag': getRandomValue(tag),
        'm_attr': [getRandomValue(attr)],
        'm_method': getRandomValue(method),
    };
}

function getPayload(target)
{
    let payload = [
        `${target}&payload=url`,
        `javascript:window.document.write('<script src={target}&payload=document.write></script>')`,
        `function(){top.mylog(${target}&payload=function)}`
    ];
    return getRandomValue(payload);
}

function createPayload()
{
    
    
    //js会自动加载 all_frames
    let frame = document.createElement('iframe');
    frame.style.display='none';
    document.body.appendChild(frame);

    let {m_tag, m_attr, m_method} = getTag();
    let target = `${url}tag=${m_tag}&attr=${m_attr}&method=${m_method}`;
    let m_payload = getPayload(target);

    let id = m_tag + escape(m_payload).substr(0,10) + Math.random();
    frame.id = id;

    // 写入测试代码
    frame.contentWindow.document.open();
    frame.contentWindow.document.write(`<script>
    function alert(m){setTimeout(function(){parent.postMessage('','*')},500);}
    function confire(m){setTimeout(function(){parent.postMessage('','*')},500);}
    function prompt(m){setTimeout(function(){parent.postMessage('','*')},500);}
    setTimeout(function() {
        document.querySelectorAll('a').forEach((element) => {
        //TODO
        //var href = element.getAttribute('href');if (href && href.indexOf('javascript:') == 0) element.click()
        var onmouseover = element.getAttribute('onmouseover')
        if (onmouseover && onmouseover.indexOf('javascript:') == 0) element.onmouseover()
    })}, 1000);
    </script>`);

    frame.contentWindow.document.write(`
            <script>
            setTimeout(
            "top.document.body.removeChild(top.document.getElementById('${id}'));"
            ,5000)
            </script>`);
    // 写入payload内容
    

    let item = document.createElement(m_tag);
    m_attr.forEach(function(value) {
        item.setAttribute(value, m_payload);
    });
    item.addEventListener(method,function(){
        let img = document.createElement('img');
        img.setAttribute('src', target);
        document.body.apptend();
    }, false);
    //frame.contentWindow.document.body.append(item);
    
    frame.contentWindow.onload = function(){frame.contentWindow.document.body.append(item)};
    frame.contentWindow.document.close();
}


if (top.location == self.location ) {
    window.onload = function(){
        //createPayload();
        //console.log('in top');
        setInterval(function(){createPayload();}, 10);
    };   
}
*/







